from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-13 14:04:27.376332
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 13, Jan, 2022
Time: 14:04:33
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6953
Nobs: 535.000 HQIC: -48.1338
Log likelihood: 6209.00 FPE: 9.40509e-22
AIC: -48.4157 Det(Omega_mle): 7.96120e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.379867 0.071606 5.305 0.000
L1.Burgenland 0.100949 0.042873 2.355 0.019
L1.Kärnten -0.112902 0.022146 -5.098 0.000
L1.Niederösterreich 0.187485 0.089157 2.103 0.035
L1.Oberösterreich 0.115047 0.088686 1.297 0.195
L1.Salzburg 0.267323 0.045290 5.902 0.000
L1.Steiermark 0.025298 0.059675 0.424 0.672
L1.Tirol 0.106270 0.048064 2.211 0.027
L1.Vorarlberg -0.076923 0.042549 -1.808 0.071
L1.Wien 0.013771 0.078411 0.176 0.861
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062161 0.156813 0.396 0.692
L1.Burgenland -0.043158 0.093890 -0.460 0.646
L1.Kärnten 0.039994 0.048499 0.825 0.410
L1.Niederösterreich -0.206660 0.195250 -1.058 0.290
L1.Oberösterreich 0.453652 0.194218 2.336 0.020
L1.Salzburg 0.286886 0.099183 2.892 0.004
L1.Steiermark 0.112521 0.130686 0.861 0.389
L1.Tirol 0.307680 0.105259 2.923 0.003
L1.Vorarlberg 0.020325 0.093179 0.218 0.827
L1.Wien -0.024232 0.171716 -0.141 0.888
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197793 0.036608 5.403 0.000
L1.Burgenland 0.091583 0.021919 4.178 0.000
L1.Kärnten -0.007492 0.011322 -0.662 0.508
L1.Niederösterreich 0.234408 0.045581 5.143 0.000
L1.Oberösterreich 0.165849 0.045340 3.658 0.000
L1.Salzburg 0.039931 0.023154 1.725 0.085
L1.Steiermark 0.024528 0.030509 0.804 0.421
L1.Tirol 0.082256 0.024573 3.347 0.001
L1.Vorarlberg 0.054845 0.021753 2.521 0.012
L1.Wien 0.117823 0.040087 2.939 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126097 0.036595 3.446 0.001
L1.Burgenland 0.041159 0.021911 1.878 0.060
L1.Kärnten -0.014281 0.011318 -1.262 0.207
L1.Niederösterreich 0.169664 0.045565 3.724 0.000
L1.Oberösterreich 0.334799 0.045324 7.387 0.000
L1.Salzburg 0.104369 0.023146 4.509 0.000
L1.Steiermark 0.109612 0.030498 3.594 0.000
L1.Tirol 0.091501 0.024564 3.725 0.000
L1.Vorarlberg 0.055382 0.021745 2.547 0.011
L1.Wien -0.018872 0.040073 -0.471 0.638
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105117 0.069483 1.513 0.130
L1.Burgenland -0.040573 0.041602 -0.975 0.329
L1.Kärnten -0.046006 0.021490 -2.141 0.032
L1.Niederösterreich 0.142255 0.086514 1.644 0.100
L1.Oberösterreich 0.172015 0.086057 1.999 0.046
L1.Salzburg 0.280209 0.043947 6.376 0.000
L1.Steiermark 0.064399 0.057907 1.112 0.266
L1.Tirol 0.154541 0.046640 3.314 0.001
L1.Vorarlberg 0.094600 0.041287 2.291 0.022
L1.Wien 0.077459 0.076087 1.018 0.309
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.089447 0.054024 1.656 0.098
L1.Burgenland 0.020908 0.032346 0.646 0.518
L1.Kärnten 0.052323 0.016708 3.132 0.002
L1.Niederösterreich 0.189806 0.067266 2.822 0.005
L1.Oberösterreich 0.327727 0.066910 4.898 0.000
L1.Salzburg 0.038215 0.034170 1.118 0.263
L1.Steiermark -0.002570 0.045023 -0.057 0.954
L1.Tirol 0.123756 0.036263 3.413 0.001
L1.Vorarlberg 0.063825 0.032101 1.988 0.047
L1.Wien 0.097834 0.059158 1.654 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166105 0.065437 2.538 0.011
L1.Burgenland 0.008335 0.039179 0.213 0.832
L1.Kärnten -0.065836 0.020238 -3.253 0.001
L1.Niederösterreich -0.110778 0.081476 -1.360 0.174
L1.Oberösterreich 0.217201 0.081045 2.680 0.007
L1.Salzburg 0.052100 0.041388 1.259 0.208
L1.Steiermark 0.252266 0.054534 4.626 0.000
L1.Tirol 0.499677 0.043923 11.376 0.000
L1.Vorarlberg 0.065399 0.038883 1.682 0.093
L1.Wien -0.080571 0.071655 -1.124 0.261
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170297 0.072377 2.353 0.019
L1.Burgenland -0.009493 0.043335 -0.219 0.827
L1.Kärnten 0.062973 0.022385 2.813 0.005
L1.Niederösterreich 0.174742 0.090118 1.939 0.052
L1.Oberösterreich -0.066221 0.089641 -0.739 0.460
L1.Salzburg 0.208155 0.045778 4.547 0.000
L1.Steiermark 0.135284 0.060318 2.243 0.025
L1.Tirol 0.055690 0.048582 1.146 0.252
L1.Vorarlberg 0.144111 0.043007 3.351 0.001
L1.Wien 0.127293 0.079256 1.606 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.399627 0.042279 9.452 0.000
L1.Burgenland -0.003419 0.025314 -0.135 0.893
L1.Kärnten -0.020348 0.013076 -1.556 0.120
L1.Niederösterreich 0.201837 0.052642 3.834 0.000
L1.Oberösterreich 0.240391 0.052364 4.591 0.000
L1.Salzburg 0.035094 0.026741 1.312 0.189
L1.Steiermark -0.018539 0.035235 -0.526 0.599
L1.Tirol 0.086728 0.028379 3.056 0.002
L1.Vorarlberg 0.050345 0.025122 2.004 0.045
L1.Wien 0.031813 0.046297 0.687 0.492
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033173 0.096088 0.159968 0.136457 0.083584 0.079348 0.024461 0.206044
Kärnten 0.033173 1.000000 -0.027532 0.132371 0.047322 0.082697 0.447419 -0.071000 0.093081
Niederösterreich 0.096088 -0.027532 1.000000 0.306572 0.123394 0.261667 0.062695 0.154381 0.276990
Oberösterreich 0.159968 0.132371 0.306572 1.000000 0.216627 0.291351 0.167621 0.130828 0.230182
Salzburg 0.136457 0.047322 0.123394 0.216627 1.000000 0.125503 0.082448 0.108032 0.126280
Steiermark 0.083584 0.082697 0.261667 0.291351 0.125503 1.000000 0.133065 0.100898 0.024505
Tirol 0.079348 0.447419 0.062695 0.167621 0.082448 0.133065 1.000000 0.064072 0.145942
Vorarlberg 0.024461 -0.071000 0.154381 0.130828 0.108032 0.100898 0.064072 1.000000 -0.009673
Wien 0.206044 0.093081 0.276990 0.230182 0.126280 0.024505 0.145942 -0.009673 1.000000